/**
 * 
 */
package PyroBots.Vue;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/** 
 * <!-- begin-UML-doc -->
 * <!-- end-UML-doc -->
 * @author glen
 * @generated "UML vers Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
 */
public class VueLog extends JPanel implements Observer {

	private JTextPane JTP_prompt;
	private JScrollPane scroll;
	
	public VueLog(){
		super();
		this.setLocation(new Point(232, 526));
		this.setSize(new Dimension(500,190));
		JTP_prompt = new JTextPane();
		JTP_prompt.setPreferredSize(new Dimension(500,190));
		JTP_prompt.setLocation(0,0);
		JTP_prompt.setAutoscrolls(true);
		//JTP_prompt.setMinimumSize());
		
		this.setVisible(true);
		scroll = new JScrollPane(JTP_prompt);
		scroll.setVerticalScrollBar(new JScrollBar());
		
		scroll.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {  
	 
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
			    e.getAdjustable().setValue(e.getAdjustable().getMaximum()); 
				
			}
	    }); 
		
		this.add(scroll);

		this.write("Bienvenue dans PyroBots...");
		

	}
	
	public void write(String mess){
		
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm:ss");
		String texte_date = sdf.format(new Date());
		
		this.JTP_prompt.setText(texte_date + " > " + mess + "\n" + JTP_prompt.getText());


	}
	@Override
	public void update(Observable o, Object arg) {

		if (arg != null)
		{

			if (arg.getClass().getName() == "java.lang.String"){
				this.write((String) arg);
		}
		}
	}
}